package housing.task2.stale.fileIO.jsn;

import housing.task1.actor.Address;
import housing.task1.actor.Renter;
import housing.task2.stale.fileIO.Parser;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

/**
 * Sttic method readRenter(String file)
 * <p/>
 * Created by IntelliJ IDEA.
 * User: Linderhof
 * Date: 18.11.2010
 * Time: 18:36:38
 */
public class Reader {
    public static ArrayList<Renter> readRenter(String file) {
        ArrayList<Renter> result = new ArrayList<Renter>();

        try {
            ArrayList<String[]> stringArrays = Parser.parseJSON(file);

            File source = new File(file);
            if (!source.exists()) {
                System.out.println("No file found!");
                return null;
            }

            String firstName;
            String lastName;
            long id;

            String street;
            int house;
            int flat;

            for (String[] str : stringArrays) {
                id = new Long(str[3]);
                firstName = str[4];
                lastName = str[5];
                street = str[0];
                house = new Integer(str[1]);
                flat = new Integer(str[2]);
                result.add(new Renter(id, firstName, lastName,
                        new Address(1, street, house, flat)));
//                System.out.println(str[0] + " " + str[1] + " " + str[2]);
            }
        }
        catch (IOException ioe) {
            ioe.printStackTrace();
            return null;
        }
        return result;
    }//read()


}//class ReaderOld
